
package br.com.translog.gui.cliente;

import br.com.translog.fachada.FachadaTranslog;
import br.com.translog.gui.outro.FrmMenuPrincipal;
import br.com.translog.modelo.PessoaJuridica;
import java.awt.HeadlessException;
import javax.swing.JOptionPane;

public class FrmClienteConsultar extends javax.swing.JFrame {

    /**
     * Creates new form FrmClienteConsultar
     */
    public FrmClienteConsultar() {
        initComponents();
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT
     * modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlClienteConsultar = new javax.swing.JPanel();
        lblConsultaCliente = new javax.swing.JLabel();
        lblCNPJ = new javax.swing.JLabel();
        lblRazaoSocial = new javax.swing.JLabel();
        lblNomeFantasia = new javax.swing.JLabel();
        lblEndereco = new javax.swing.JLabel();
        lblNumero = new javax.swing.JLabel();
        lblCEP = new javax.swing.JLabel();
        lblComplemento = new javax.swing.JLabel();
        lblBairro = new javax.swing.JLabel();
        lblCidade = new javax.swing.JLabel();
        lblEstado = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        lblTelefoneComercial = new javax.swing.JLabel();
        lblSite = new javax.swing.JLabel();
        txtCNPJ = new javax.swing.JTextField();
        txtRazaoSocial = new javax.swing.JTextField();
        txtNomeFantasia = new javax.swing.JTextField();
        txtEndereco = new javax.swing.JTextField();
        txtNumero = new javax.swing.JTextField();
        txtCEP = new javax.swing.JTextField();
        txtComplemento = new javax.swing.JTextField();
        txtBairro = new javax.swing.JTextField();
        txtCidade = new javax.swing.JTextField();
        txtEstado = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        txtTelefoneComercial = new javax.swing.JTextField();
        txtSite = new javax.swing.JTextField();
        btnPesquisar = new javax.swing.JButton();
        btnVoltar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(966, 300));

        pnlClienteConsultar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        pnlClienteConsultar.setMaximumSize(new java.awt.Dimension(946, 278));
        pnlClienteConsultar.setMinimumSize(new java.awt.Dimension(946, 278));

        lblConsultaCliente.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblConsultaCliente.setText("CONSULTAR CLIENTE");
        lblConsultaCliente.setName(""); // NOI18N

        lblCNPJ.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCNPJ.setText("CNPJ");

        lblRazaoSocial.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblRazaoSocial.setText("Razão social");

        lblNomeFantasia.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblNomeFantasia.setText("Nome Fantasia");

        lblEndereco.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEndereco.setText("Endereço");

        lblNumero.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblNumero.setText("Número");

        lblCEP.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCEP.setText("CEP");

        lblComplemento.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblComplemento.setText("Complemento");

        lblBairro.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblBairro.setText("Bairro");

        lblCidade.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblCidade.setText("Cidade");

        lblEstado.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEstado.setText("Estado");

        lblEmail.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblEmail.setText("Email");

        lblTelefoneComercial.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblTelefoneComercial.setText("Telefone Comercial");

        lblSite.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        lblSite.setText("Site");

        txtRazaoSocial.setEditable(false);

        txtNomeFantasia.setEditable(false);

        txtEndereco.setEditable(false);

        txtNumero.setEditable(false);

        txtCEP.setEditable(false);

        txtComplemento.setEditable(false);

        txtBairro.setEditable(false);

        txtCidade.setEditable(false);

        txtEstado.setEditable(false);

        txtEmail.setEditable(false);

        txtTelefoneComercial.setEditable(false);

        txtSite.setEditable(false);

        btnPesquisar.setText("Pesquisar");
        btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesquisarActionPerformed(evt);
            }
        });

        btnVoltar.setText("Voltar Menu Principal");
        btnVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoltarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlClienteConsultarLayout = new javax.swing.GroupLayout(pnlClienteConsultar);
        pnlClienteConsultar.setLayout(pnlClienteConsultarLayout);
        pnlClienteConsultarLayout.setHorizontalGroup(
            pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                        .addComponent(lblRazaoSocial)
                        .addGap(18, 18, 18)
                        .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblNumero)
                                .addGap(18, 18, 18)
                                .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblCEP)
                                .addGap(18, 18, 18)
                                .addComponent(txtCEP))
                            .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lblConsultaCliente)
                                    .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                        .addComponent(txtRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblNomeFantasia)))
                                .addGap(18, 18, 18)
                                .addComponent(txtNomeFantasia))))
                    .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                        .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                .addComponent(lblEmail)
                                .addGap(53, 53, 53)
                                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtSite, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                        .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblTelefoneComercial)
                                        .addGap(18, 18, 18)
                                        .addComponent(txtTelefoneComercial, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(lblSite)
                            .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblComplemento)
                                    .addComponent(lblCNPJ)
                                    .addComponent(lblEndereco))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                        .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(btnPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(btnVoltar))
                                    .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                                        .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblBairro)
                                        .addGap(18, 18, 18)
                                        .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblCidade)
                                        .addGap(27, 27, 27)
                                        .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(lblEstado)
                                        .addGap(18, 18, 18)
                                        .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        pnlClienteConsultarLayout.setVerticalGroup(
            pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlClienteConsultarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblConsultaCliente)
                .addGap(18, 18, 18)
                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCNPJ)
                    .addComponent(txtCNPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnPesquisar)
                    .addComponent(btnVoltar))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRazaoSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNomeFantasia)
                    .addComponent(txtNomeFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblRazaoSocial))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEndereco)
                    .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNumero)
                    .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCEP)
                    .addComponent(txtCEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblComplemento)
                    .addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblBairro)
                    .addComponent(lblCidade)
                    .addComponent(lblEstado)
                    .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTelefoneComercial)
                    .addComponent(txtTelefoneComercial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlClienteConsultarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSite)
                    .addComponent(txtSite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlClienteConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlClienteConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesquisarActionPerformed

        //Instanciando os objetos que serao utilizados...
        PessoaJuridica pj;  
        
        try {
            //Verifica se o campo de pesquisa nao esta em "branco"...
            if (!txtCNPJ.getText().equals("")) {
                pj = FachadaTranslog.getInstFachadaTranslog().consultaCliente(Integer.parseInt(txtCNPJ.getText()));
                //JOptionPane.showMessageDialog(null, pj.getCnpj());
                if (pj == null) {
                    JOptionPane.showMessageDialog(null, "Cliente não Encontrado!");
                } else {
                    //Setando os valores do objeto cliente nos JTextFields...
                    txtBairro.setText(pj.getCliente().getCodigoLogradouro().getCodigoBairro().getNome());
                    txtCEP.setText(String.valueOf(pj.getCliente().getCodigoLogradouro().getCep()));
                    txtCidade.setText(pj.getCliente().getCodigoLogradouro().getCodigoCidade().getNome());
                    txtCNPJ.setText(String.valueOf(pj.getCnpj()));
                    txtComplemento.setText(pj.getCliente().getCodigoLogradouro().getComplemento());
                    txtEmail.setText(pj.getEmail());
                    txtEndereco.setText(pj.getCliente().getCodigoLogradouro().getEndereco());
                    txtEstado.setText(pj.getCliente().getCodigoLogradouro().getCodigoEstado().getNome());
                    txtNomeFantasia.setText(pj.getNomeFantasia());
                    txtNumero.setText(pj.getCliente().getCodigoLogradouro().getNumero());
                    txtRazaoSocial.setText(pj.getRazaoSocial());
                    txtSite.setText(pj.getSite());
                    txtTelefoneComercial.setText(String.valueOf(pj.getTelefoneComercial()));
                    
                }
                
            } else {
                JOptionPane.showMessageDialog(null, "Dados Obrigatórios não Informados!");
            }
            
        } catch (NumberFormatException | HeadlessException e) {
        }       
    }//GEN-LAST:event_btnPesquisarActionPerformed

    private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoltarActionPerformed
        
        new FrmMenuPrincipal().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_btnVoltarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmClienteConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmClienteConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmClienteConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmClienteConsultar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new FrmClienteConsultar().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnPesquisar;
    private javax.swing.JButton btnVoltar;
    private javax.swing.JLabel lblBairro;
    private javax.swing.JLabel lblCEP;
    private javax.swing.JLabel lblCNPJ;
    private javax.swing.JLabel lblCidade;
    private javax.swing.JLabel lblComplemento;
    private javax.swing.JLabel lblConsultaCliente;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblEndereco;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblNomeFantasia;
    private javax.swing.JLabel lblNumero;
    private javax.swing.JLabel lblRazaoSocial;
    private javax.swing.JLabel lblSite;
    private javax.swing.JLabel lblTelefoneComercial;
    private javax.swing.JPanel pnlClienteConsultar;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JTextField txtCEP;
    private javax.swing.JTextField txtCNPJ;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JTextField txtComplemento;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtEndereco;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtNomeFantasia;
    private javax.swing.JTextField txtNumero;
    private javax.swing.JTextField txtRazaoSocial;
    private javax.swing.JTextField txtSite;
    private javax.swing.JTextField txtTelefoneComercial;
    // End of variables declaration//GEN-END:variables
}
